package com.yugu.park.system.service.impl;

import org.springframework.stereotype.Service;

import java.util.List;
import javax.annotation.Resource;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Transactional;
import com.github.pagehelper.PageInfo;
import com.yugu.util.SearchPage;
import com.yugu.util.StringUtils;

import cn.hutool.core.lang.UUID;

import com.yugu.park.system.mapper.SysDictTypeMapper;
import com.yugu.park.system.entity.SysDictTypeEntity;
import com.yugu.park.system.service.SysDictTypeService;
import com.github.pagehelper.PageHelper;

@Service
@Transactional
public class SysDictTypeServiceImpl extends ServiceImpl<SysDictTypeMapper, SysDictTypeEntity> implements SysDictTypeService {
      @Resource
	  private SysDictTypeMapper mapper;
	@Override
	public PageInfo<SysDictTypeEntity> page(SearchPage<SysDictTypeEntity> search) {
		PageHelper.startPage(search.getPageNum(),search.getPageSize());
        List<SysDictTypeEntity> list = mapper.page(search.getSearch());
        return PageInfo.of(list);
	}
	@Override
	public void addOrUpdate(SysDictTypeEntity t) {
		SysDictTypeEntity old = mapper.selectById(t.getId());
		if(old!=null) {
			String dictName = t.getDictName();
			if(StringUtils.isNotEmpty(dictName)) {
				old.setDictName(dictName);
			}
			String dictType = t.getDictType();
			if(StringUtils.isNotEmpty(dictType)) {
				old.setDictType(dictType);
			}
			String remark = t.getRemark();
			if(StringUtils.isNotEmpty(remark)) {
				old.setRemark(remark);
			}
			String status = t.getStatus();
			if(StringUtils.isNotEmpty(status)) {
				old.setStatus(status);
			}
			mapper.updateById(old);
		}else{
			t.setId(UUID.randomUUID().toString().replaceAll("-", ""));
			mapper.insert(t);
		}
	}

}
